/*****************************************************************************/
/**
 *  @file   DataSet.cpp
 *  @author Naohisa Sakamoto
 */
/*----------------------------------------------------------------------------
 *
 *  Copyright (c) Visualization Laboratory, Kyoto University.
 *  All rights reserved.
 *  See http://www.viz.media.kyoto-u.ac.jp/kvs/copyright/ for details.
 *
 *  $Id$
 */
/*****************************************************************************/
#include "DataSet.h"
#include <kvs/StructuredVolumeImporter>
#include <kvs/CellByCellMetropolisSampling>

typedef kvs::CellByCellMetropolisSampling Sampler;


DataSet::DataSet( const std::string& filename ):
    m_filename( filename )
{
    this->loadVolume();
}

void DataSet::loadVolume()
{
    m_volume = Volume( new kvs::StructuredVolumeImporter( m_filename ) );
    m_volume->setName( "Volume" );

    // TEST IMPLEMENTATION
    kvs::Vector3ui resolution = m_volume->resolution();
    size_t ndivs = 7;
    size_t div_dimx = resolution.x() / ndivs;
    size_t div_dimy = resolution.y() / ndivs;
    size_t div_dimz = resolution.z() / ndivs;
    for ( size_t k = 0; k < ndivs; k++ )
    {
        for ( size_t j = 0; j < ndivs; j++ )
        {
            for ( size_t i = 0; i < ndivs; i++ )
            {
                const size_t I = i + 1;
                const size_t J = j + 1;
                const size_t K = k + 1;
                const kvs::Vec3 min( div_dimx * i, div_dimy * j, div_dimz * k );
                const kvs::Vec3 max( div_dimx * I, div_dimy * J, div_dimz * K );
                Range range; range.min = min; range.max = max;
                m_bounds.ranges.push_back( range );
            }
        }
    }
}

void DataSet::generateParticles( const size_t repeats, const kvs::TransferFunction& tfunc )
{
    const size_t level = static_cast<size_t>( std::sqrt( double( repeats ) ) );
    const float step = 0.5f;
    m_particles = Particles( new Sampler( m_volume.get(), level, step, tfunc ) );
    m_particles->setName( "Particles" );
}
